package logic

import (
	"context"
	"fmt"
	"go.uber.org/zap"
	"order_srv/internal/dao"
	"order_srv/internal/svc"
	"order_srv/order"
	"smart-health-platforms/pkg"

	"github.com/zeromicro/go-zero/core/logx"
)

type GetAfterSaleLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewGetAfterSaleLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetAfterSaleLogic {
	return &GetAfterSaleLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *GetAfterSaleLogic) GetAfterSale(in *order.GetAfterSaleRequest) (*order.GetAfterSaleResponse, error) {
	afterSale, err := dao.GetAfterSale(in)
	if err != nil {
		pkg.Error("获取售后信息失败", zap.Error(err))
		return nil, fmt.Errorf("获取售后信息失败")
	}

	return &order.GetAfterSaleResponse{
		OrderId:      int64(afterSale.OrderId),
		UserId:       int64(afterSale.UserId),
		Type:         int32(afterSale.Type),
		Reason:       afterSale.Reason,
		RefundAmount: afterSale.RefundAmount,
		Images:       afterSale.Images,
		Status:       int64(afterSale.Status),
	}, nil
}
